package com.cennavi.buss.controller;

import com.cennavi.buss.service.imp.ISearchService;
import com.cennavi.minemap.bean.MessageBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/service", produces = "application/json; charset=UTF-8")
@Api(value = "Search controller", description = "Search controller")
public class SearchController {

    @Autowired
    private ISearchService iSearchService;

    /**
     * 关键字搜索
     * <p>
     * 新接口{@link SearchController#keyword2(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.Integer, java.lang.String, java.lang.String, java.lang.Integer, java.lang.Integer)}
     */
    @Deprecated
    @ApiOperation(value = "关键字搜索")
    @RequestMapping(method = RequestMethod.GET, value = {"/search2/keyword",
            "/search/keyword"}, produces = "application/json; charset=UTF-8")
    public MessageBean keyword(@RequestParam("token") String token,
                               @RequestParam(value = "adCode", defaultValue = "") String adCode, @RequestParam("key") String key,
                               @RequestParam(value = "searchType", defaultValue = "all") String searchType,
                               @RequestParam(value = "dataType", defaultValue = "") String dataType,
                               @RequestParam(value = "pageNumber", defaultValue = "1") Integer pageNumber,
                               @RequestParam(value = "pageCount", defaultValue = "10") Integer pageCount,
                               @RequestParam(value = "source", defaultValue = "1") Integer source) {
        return iSearchService.keyword(token, adCode, key, searchType, dataType, pageNumber, pageCount, source);
    }

    @ApiOperation(value = "周边搜索")
    @RequestMapping(method = RequestMethod.GET, value = {"/search/surround",
            "/search2/surround"}, produces = "application/json; charset=UTF-8")
    public MessageBean surround(@RequestParam("token") String token,
                                @RequestParam(value = "adCode", defaultValue = "") String adCode, @RequestParam("key") String key,
                                @RequestParam(value = "searchType", defaultValue = "all") String searchType,
                                @RequestParam(value = "dataType", defaultValue = "") String dataType,
                                @RequestParam(value = "pageNumber", defaultValue = "1") Integer pageNumber,
                                @RequestParam(value = "pageCount", defaultValue = "10") Integer pageCount,
                                @RequestParam(value = "source", defaultValue = "1") Integer source,
                                @RequestParam(value = "location") String location,
                                @RequestParam(value = "inRadius", defaultValue = "0") Integer inRadius,
                                @RequestParam(value = "spatialFunction", defaultValue = "geofilt") String spatialFunction,
                                @RequestParam(value = "radius", defaultValue = "500") Integer radius,
                                @RequestParam(value = "seq", defaultValue = "0") Integer seq) {
        return iSearchService.surround(token, adCode, key, searchType, dataType, pageNumber, pageCount, source,
                location, inRadius, spatialFunction, radius, seq);
    }

    @RequestMapping(method = RequestMethod.GET, value = {"/search/bbox",
            "/search2/bbox"}, produces = "application/json; charset=UTF-8")
    public MessageBean bbox(@RequestParam("token") String token,
                            @RequestParam(value = "adCode", defaultValue = "") String adCode, @RequestParam("key") String key,
                            @RequestParam("bounds") String bounds,
                            @RequestParam(value = "searchType", defaultValue = "all") String searchType,
                            @RequestParam(value = "dataType", defaultValue = "") String dataType,
                            @RequestParam(value = "pageNumber", defaultValue = "1") Integer pageNumber,
                            @RequestParam(value = "pageCount", defaultValue = "10") Integer pageCount,
                            @RequestParam(value = "source", defaultValue = "1") Integer source,
                            @RequestParam(value = "seq", defaultValue = "0") Integer seq) {
        return iSearchService.bbox(token, adCode, key, bounds, searchType, dataType, pageNumber, pageCount, source,
                seq);
    }

    @RequestMapping(method = RequestMethod.GET, value = {"/route/driving",
            "/route2/driving"}, produces = "application/json; charset=UTF-8")
    public MessageBean driving(@RequestParam("token") String token, @RequestParam("sPoint") String sPoint,
                               @RequestParam("ePoint") String ePoint,
                               @RequestParam(value = "wayPoints", defaultValue = "") String wayPoints,
                               @RequestParam(value = "shpFlag", defaultValue = "1") Integer shpFlag,
                               @RequestParam(value = "costModel", defaultValue = "16") Integer costModel,
                               @RequestParam(value = "vehicleSpeed", defaultValue = "0") Integer vehicleSpeed,
                               @RequestParam(value = "numAlt", defaultValue = "1") Integer numAlt,
                               @RequestParam(value = "criteria", defaultValue = "0") Integer criteria,
                               @RequestParam(value = "source", defaultValue = "1") String source,
                               @RequestParam(value = "traffic", defaultValue = "0") Integer traffic) {
        return iSearchService.driving(token, sPoint, ePoint, wayPoints, shpFlag, costModel, vehicleSpeed, numAlt,
                criteria, source, traffic);
    }

    /**
     * 路线规划
     * <p>
     * 新接口{@link SearchController#newDriving2(java.lang.String, java.lang.String, java.lang.Integer, java.lang.String, java.lang.String)}
     */
    @Deprecated
    @ApiOperation(value = "路线规划")
    @RequestMapping(method = RequestMethod.GET, value = {"/route/driving2",
            "/route2/driving2"}, produces = "application/json; charset=UTF-8")
    public MessageBean newDriving(@RequestParam("token") String token,
                                  @RequestParam(value = "source", defaultValue = "3") String source, @RequestParam("sPoint") String sPoint,
                                  @RequestParam("ePoint") String ePoint,
                                  @RequestParam(value = "wayPoints", defaultValue = "") String wayPoints,
                                  @RequestParam(value = "st", defaultValue = "4") Integer st,
                                  @RequestParam(value = "avoidArea", defaultValue = "") String avoidArea) {
        return iSearchService.newDriving(token, source, sPoint, ePoint, wayPoints, st, avoidArea);
    }

    /**
     * 公交换乘-经纬度查询
     * <p>
     * 新接口{@link SearchController#busTransfer2(java.lang.String, java.lang.String, java.lang.String, java.lang.Integer)}
     */
    @Deprecated
    @ApiOperation(value = "公交换乘-经纬度查询")
    @RequestMapping(method = RequestMethod.GET, value = {"/route/busTransfer",
            "/route2/busTransfer"}, produces = "application/json; charset=UTF-8")
    public MessageBean busTransfer(@RequestParam("token") String token,
                                   @RequestParam("adCode") String adCode,
                                   @RequestParam(value = "strategy", defaultValue = "0") Integer strategy,
                                   @RequestParam(value = "shpInfoFlag", defaultValue = "1") Integer shpInfoFlag,
                                   @RequestParam("sPoint") String sPoint, @RequestParam("ePoint") String ePoint,
                                   @RequestParam(value = "showWalkInfo", defaultValue = "0") Integer showWalkInfo,
                                   @RequestParam(value = "source", defaultValue = "1") Integer source) {
        return iSearchService.busTransfer(token, adCode, strategy, shpInfoFlag, sPoint, ePoint, showWalkInfo, source);
    }

    @RequestMapping(method = RequestMethod.GET, value = {"/search/adminByPoint",
            "/search2/adminByPoint"}, produces = "application/json; charset=UTF-8")
    public MessageBean adminByPoint(@RequestParam("token") String token,
                                    @RequestParam("location") String location,
                                    @RequestParam(value = "geometry", defaultValue = "0") Integer geometry,
                                    @RequestParam(value = "source", defaultValue = "1") Integer source,
                                    @RequestParam(value = "language", defaultValue = "0") Integer language) {
        return iSearchService.adminByPoint(token, location, geometry, source, language);
    }

    /**
     * 地理编码 POI 搜索
     * <p>
     * 新接口{@link SearchController#geocoding2(java.lang.String, java.lang.String, java.lang.Integer, java.lang.Integer)}
     */
    @Deprecated
    @ApiOperation(value = "地理编码 POI 搜索")
    @RequestMapping(method = RequestMethod.GET, value = {"/coder/geocoding",
            "/coder2/geocoding"}, produces = "application/json; charset=UTF-8")
    public MessageBean geocoding(@RequestParam("token") String token,
                                 @RequestParam("address") String address, @RequestParam("adCode") String adCode,
                                 @RequestParam(value = "source", defaultValue = "1") Integer source) {
        return iSearchService.geocoding(token, address, adCode, source);
    }

    /**
     * 地理编码评分
     * <p>
     * 新接口{@link SearchController#geocodingScore2(java.lang.String, java.lang.String)}
     */
    @Deprecated
    @ApiOperation(value = "地理编码评分")
    @RequestMapping(method = RequestMethod.GET, value = {"/coder/geocoding/score",
            "/coder2/geocoding/score"}, produces = "application/json; charset=UTF-8")
    public MessageBean geocodingScore(@RequestParam("token") String token,
                                      @RequestParam("address") String address,
                                      @RequestParam(value = "adCode", defaultValue = "") String adCode) {
        return iSearchService.geocodingScore(token, address, adCode);
    }

    /**
     * 逆地理编码查询
     * <p>
     * 新接口{@link SearchController#reverseGeocoding2(java.lang.String, java.lang.Integer, java.lang.Integer, java.lang.Integer)}
     */
    @Deprecated
    @ApiOperation(value = "逆地理编码查询")
    @RequestMapping(method = RequestMethod.GET, value = {"/coder/reverseGeocoding",
            "/coder2/reverseGeocoding"}, produces = "application/json; charset=UTF-8")
    public MessageBean reverseGeocoding(@RequestParam("token") String token,
                                        @RequestParam("location") String location, @RequestParam(value = "type", defaultValue = "1") Integer type,
                                        @RequestParam(value = "radius", defaultValue = "300") Integer radius,
                                        @RequestParam(value = "roadRadius", defaultValue = "300") Integer roadRadius,
                                        @RequestParam(value = "kind", defaultValue = "0") Integer kind,
                                        @RequestParam(value = "source", defaultValue = "1") Integer source) {
        return iSearchService.reverseGeocoding(token, location, type, radius, roadRadius, kind, source);
    }

    @RequestMapping(method = RequestMethod.GET, value = {"/search/around",
            "/search2/around"}, produces = "application/json; charset=UTF-8")
    public MessageBean around(@RequestParam("token") String token,
                              @RequestParam("location") String location, @RequestParam("type") String type,
                              @RequestParam(value = "radius", defaultValue = "1000") Integer radius,
                              @RequestParam(value = "count", defaultValue = "5") Integer count) {
        return iSearchService.around(token, location, type, radius, count);
    }

    @RequestMapping(method = RequestMethod.GET, value = {"/tips/smartTips",
            "/tips2/smartTips"}, produces = "application/json; charset=UTF-8")
    public MessageBean smartTips(@RequestParam("token") String token, @RequestParam("input") String input,
                                 @RequestParam("adCode") int adCode,
                                 @RequestParam(value = "searchType", defaultValue = "all") String searchType,
                                 @RequestParam(value = "pageCount", defaultValue = "10") Integer pageCount) {
        return iSearchService.smartTips(token, input, adCode, searchType, pageCount);
    }

    /**
     * 公交线路关键字查询
     * <p>
     * 新接口{@link SearchController#busRoute2(java.lang.String, java.lang.String, java.lang.String, java.lang.Boolean, java.lang.Integer, java.lang.Integer)}
     */
    @Deprecated
    @ApiOperation(value = "公交线路关键字查询")
    @RequestMapping(method = RequestMethod.GET, value = {"/route/busRoute",
            "/route2/busRoute"}, produces = "application/json; charset=UTF-8")
    public MessageBean busRoute(@RequestParam("adCode") String adCode,
                                @RequestParam(value = "keyword") String keyword) {
        return iSearchService.busRoute(adCode, keyword);
    }

    /**
     * 公交站点关键字查询
     * <p>
     * 新接口{@link SearchController#busStation2(java.lang.String, java.lang.String, java.lang.Integer, java.lang.Integer)}
     */
    @Deprecated
    @ApiOperation(value = "公交站点关键字查询")
    @RequestMapping(method = RequestMethod.GET, value = {"/route/busStation",
            "/route2/busStation"}, produces = "application/json; charset=UTF-8")
    public MessageBean busStation(@RequestParam("adCode") String adCode,
                                  @RequestParam(value = "keyword") String keyword) {
        return iSearchService.busStation(adCode, keyword);
    }

    @RequestMapping(method = RequestMethod.GET, value = {"/search/suggest",
            "/search2/suggest"}, produces = "application/json; charset=UTF-8")
    public MessageBean suggest(@RequestParam(value = "keywords") String keywords,
                               @RequestParam("city") String city) {
        return iSearchService.suggest(keywords, city);
    }

    /* --------------------------------------------- minemap 接口调整 ------------------------------------------------ */

    /**
     * 一框搜索(新)
     */
    @ApiOperation(value = "一框搜索(新))")
    @GetMapping("/search/keyword2")
    public MessageBean keyword2(@ApiParam("adcode/城市名称") @RequestParam(value = "city", defaultValue = "") String city,
                                @ApiParam("关键字") @RequestParam("keywords") String keywords,
                                @ApiParam("关键字搜索:搜索指定位置，若area和zoom为空，则默认为该位置所在城市;周边搜索:指定位置，和range配合使用") @RequestParam("location") String location,
                                @ApiParam("(关键字搜索使用)当前视野的经纬度坐标（02坐标）") @RequestParam(value = "area", required = false) String area,
                                @ApiParam("(周边搜索使用)周边搜索指定范围") @RequestParam(value = "range", defaultValue = "3000") String range,
                                @ApiParam("(关键字搜索使用)缩放级别") @RequestParam(value = "zoom", defaultValue = "12") Integer zoom,
                                @ApiParam("搜索类型") @RequestParam(value = "search_type", defaultValue = "normal") String searchType,
                                @ApiParam("语言") @RequestParam(value = "language", defaultValue = "zh_CN") String language,
                                @ApiParam("当前页数") @RequestParam(value = "page_num", defaultValue = "1") Integer pageNum,
                                @ApiParam("每页记录数") @RequestParam(value = "page_size", defaultValue = "10") Integer pageSize) {
        return iSearchService.keywordSearch(city, keywords, location, area, range, zoom, searchType, language, pageNum, pageSize);
    }

    /**
     * 地理编码评分(新)
     * <p>
     * 原接口{@link SearchController#geocodingScore(java.lang.String, java.lang.String, java.lang.String)}
     */
    @ApiOperation(value = "地理编码评分(新)")
    @GetMapping("/coder/geocoding/score2")
    public MessageBean geocodingScore2(@ApiParam("关键字") @RequestParam("keywords") String keywords,
                                       @ApiParam("adcode/城市名称") @RequestParam("city") String city) {
        return iSearchService.geocodingScore2(keywords, city);
    }

    /**
     * 路线规划(新)
     * <p>
     * 原接口{@link SearchController#newDriving(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.Integer, java.lang.String)}
     */
    @ApiOperation(value = "路线规划(新)")
    @GetMapping("/route/driving3")
    public MessageBean newDriving2(@ApiParam("起点坐标") @RequestParam("sPoint") String sPoint,
                                   @ApiParam("终点坐标") @RequestParam("ePoint") String ePoint,
                                   @ApiParam("算路模式") @RequestParam(value = "st", defaultValue = "4") Integer st,
                                   @ApiParam("途经点") @RequestParam(value = "wayPoints", defaultValue = "") String wayPoints,
                                   @ApiParam("避让区域") @RequestParam(value = "avoidArea", defaultValue = "") String avoidArea) {
        return iSearchService.newDriving2(sPoint, ePoint, st, wayPoints, avoidArea);
    }

    /**
     * 货车-路线规划(新)
     */
    @ApiOperation(value = "货车路线规划(新)")
    @GetMapping("/route/truck-driving")
    public MessageBean truckDriving(@ApiParam("起点坐标") @RequestParam("sPoint") String sPoint,
                                    @ApiParam("终点坐标") @RequestParam("ePoint") String ePoint,
                                    @ApiParam("算路模式") @RequestParam(value = "st", defaultValue = "4", required = false) Integer st,
                                    @ApiParam("途经点") @RequestParam(value = "wayPoints", defaultValue = "", required = false) String wayPoints,
                                    @ApiParam("避让区域") @RequestParam(value = "avoidArea", defaultValue = "", required = false) String avoidArea,
                                    @ApiParam("长度") @RequestParam(value = "length", required = false) Double length,
                                    @ApiParam("高度") @RequestParam(value = "height", required = false) Double height,
                                    @ApiParam("宽度") @RequestParam(value = "width", required = false) Double width,
                                    @ApiParam("货车重量") @RequestParam(value = "weight", required = false) Integer weight,
                                    @ApiParam("轴重") @RequestParam(value = "axleWeight", required = false) Integer axleWeight,
                                    @ApiParam("轴数") @RequestParam(value = "axleCount", required = false) Integer axleCount,
                                    @ApiParam("是否拥有通行证") @RequestParam(value = "hasPassport", defaultValue = "true", required = false) Boolean hasPassport,
                                    @ApiParam("车辆能源类型") @RequestParam(value = "energyType", required = false) Integer energyType,
                                    @ApiParam("机动车污染物排放标准") @RequestParam(value = "emissionStandard", required = false) Integer emissionStandard,
                                    @ApiParam("货车负载类型") @RequestParam(value = "truckLoadType", required = false) Integer truckLoadType,
                                    @ApiParam("货车类型") @RequestParam(value = "truckType", required = false) Integer truckType,
                                    @ApiParam("货车功能") @RequestParam(value = "truckFunction", required = false) Integer truckFunction,
                                    @ApiParam("车牌号") @RequestParam(value = "plateNumber", required = false) Integer plateNumber) {
        return iSearchService.truckDriving(sPoint, ePoint, st, wayPoints,
                avoidArea, length, height, width, weight, axleWeight, axleCount,
                hasPassport, energyType, emissionStandard, truckLoadType, truckType, truckFunction, plateNumber);
    }

    /**
     * 公交换乘-经纬度查询(新)
     * <p>
     * 原接口{@link SearchController#busTransfer(java.lang.String, java.lang.String, java.lang.Integer, java.lang.Integer, java.lang.String, java.lang.String, java.lang.Integer, java.lang.Integer)}
     */
    @ApiOperation(value = "公交换乘-经纬度查询(新)")
    @GetMapping("/route/bus-transfer")
    public MessageBean busTransfer2(@ApiParam("行政区划编码或城市名称") @RequestParam("city") String city,
                                    @ApiParam("起点坐标") @RequestParam("sPoint") String sPoint,
                                    @ApiParam("终点坐标") @RequestParam("ePoint") String ePoint,
                                    @ApiParam("换乘策略") @RequestParam(value = "strategy", defaultValue = "0") Integer strategy) {
        return iSearchService.busTransfer2(city, sPoint, ePoint, strategy);
    }

    /**
     * 公交站点关键字查询(新)
     * <p>
     * 原接口{@link SearchController#busStation(java.lang.String, java.lang.String)}
     */
    @ApiOperation(value = "公交站点关键字查询(新)")
    @GetMapping("/route/bus-station")
    public MessageBean busStation2(@ApiParam("关键字") @RequestParam("keyword") String keyword,
                                   @ApiParam("城市名称") @RequestParam("city") String city,
                                   @ApiParam("当前页数") @RequestParam(name = "pn", defaultValue = "1") Integer pn,
                                   @ApiParam("每页显示数") @RequestParam(name = "rn", defaultValue = "20") Integer rn) {
        return iSearchService.busStation2(keyword, city, pn, rn);
    }

    /**
     * 公交线路关键字查询
     * <p>
     * 原接口{@link SearchController#busRoute(java.lang.String, java.lang.String)}
     */
    @ApiOperation(value = "公交线路关键字查询(新)")
    @GetMapping("/route/bus-route")
    public MessageBean busRoute2(@ApiParam("城市名称") @RequestParam("city") String city,
                                 @ApiParam("关键字") @RequestParam("keyword") String keyword,
                                 @ApiParam("查询方式") @RequestParam(name = "type", defaultValue = "name") String type,
                                 @ApiParam("是否显示返程线路信息") @RequestParam(name = "opposite", defaultValue = "false") Boolean opposite,
                                 @ApiParam("当前页数") @RequestParam(name = "pn", defaultValue = "1") Integer pn,
                                 @ApiParam("每页显示数") @RequestParam(name = "rn", defaultValue = "20") Integer rn) {
        return iSearchService.busRoute2(city, keyword, type, opposite, pn, rn);
    }

    /**
     * 地理编码 POI 搜索(新)
     * <p>
     * 原接口{@link SearchController#geocoding(java.lang.String, java.lang.String, java.lang.String, java.lang.Integer)}
     */
    @Deprecated
    @ApiOperation(value = "地理编码 POI 搜索(新)")
    @GetMapping("/coder/geocoding2")
    public MessageBean geocoding2(@ApiParam("关键字") @RequestParam("keywords") String keywords,
                                  @ApiParam("adcode/城市名称") @RequestParam("city") String city,
                                  @ApiParam("当前页数") @RequestParam(value = "page_num", defaultValue = "1") Integer pageNum,
                                  @ApiParam("每页记录数") @RequestParam(value = "page_size", defaultValue = "10") Integer pageSize) {
        return iSearchService.geocoding2(keywords, city, pageNum, pageSize);
    }


    /**
     * 逆地理编码查询(新)
     * <p>
     * 原接口{@link SearchController#reverseGeocoding(java.lang.String, java.lang.String, java.lang.Integer, java.lang.Integer, java.lang.Integer, java.lang.Integer, java.lang.Integer)}
     */
    @ApiOperation(value = "逆地理编码查询(新)")
    @GetMapping(value = "/coder/reverse-geocoding", produces = "application/json; charset=UTF-8")
    public MessageBean reverseGeocoding2(@ApiParam("经纬度") @RequestParam("location") String location,
                                         @ApiParam("是否显示带有地标点的完整详细信息详细信息") @RequestParam(value = "detail", defaultValue = "0") Integer detail,
                                         @ApiParam("是否显示道路信息") @RequestParam(value = "road", defaultValue = "0") Integer road,
                                         @ApiParam("返回数量") @RequestParam(value = "rowNumber", defaultValue = "0") Integer rowNumber) {
        return iSearchService.reverseGeocoding2(location, detail, road, rowNumber);
    }

    /**
     * 行政区信息查询(新)
     */
    @ApiOperation(value = "行政区信息查询", notes = "包括行政区中心点及行政区边界信息查询")
    @GetMapping(value = "/search/admin", produces = "application/json; charset=UTF-8")
    public MessageBean adminSearch(@ApiParam("行政区名称") @RequestParam("keywords") String keywords,
                                   @ApiParam("搜索指定位置(默认坐标为北京市中心点坐标)")
                                   @RequestParam(name = "location", defaultValue = "") String location) {
        return iSearchService.adminSearch(keywords, location);
    }
}
